package com.yanqu.road.server.cmd.activity.diggold;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DigGoldProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.diggold.DigGoldModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = GameProtocol.S_DIG_GOLD_GET_PALACE_REWARD, desc = "领取地宫宝箱奖励")
public class DigGoldGetPalaceBoxRewardCmd extends AbstractCommand {

    private int activityId;

    private int mapIndex;

    private List<Integer> boxIndex;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        DigGoldProto.GetPalaceRewardReq req = DigGoldProto.GetPalaceRewardReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        mapIndex = req.getMapIndex();
        boxIndex = new ArrayList<>(req.getBoxIndexList());

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(DigGoldModule.class).getPalaceBoxReward(activityId, mapIndex, boxIndex);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret!=0){
            DigGoldProto.GetPalaceRewardResp.Builder builder = DigGoldProto.GetPalaceRewardResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DIG_GOLD_GET_PALACE_REWARD, builder);
        }
    }
}
